//
//  MineTableViewController.m
//  Books
//
//  Created by tao故乡的云 on 2017/3/8.
//  Copyright © 2017年 故乡的云. All rights reserved.
//

#import "MineTableViewController.h"
#import "MineHeaderView.h"
#import "TLMapViewController.h"

@interface MineTableViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation MineTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuseIdentifier"];
    
    CGRect frame = CGRectMake(0, 0, self.tableView.bounds.size.height, 150);
    UIView *headerView = [MineHeaderView mineHeaderView];
    headerView.frame = frame;
//    headerView.backgroundColor = [UIColor colorWithRed:0.4 green:0.1 blue:0.8 alpha:1.0];
    self.tableView.tableHeaderView = headerView;

    self.tableView.alwaysBounceVertical = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    if (section) {
        return 4;
    }
    
    return 6;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseIdentifier" forIndexPath:indexPath];
    cell.textLabel.text = [NSString stringWithFormat:@"数据----%ld",(long)indexPath.row];
    if (indexPath.row == 0 && indexPath.section == 0) {
        cell.textLabel.text = [NSString stringWithFormat:@"我的位置"];
        [cell.imageView setImage:[UIImage imageNamed:@"chatBar_colorMore_location"]];
        [cell.imageView setHighlightedImage:[UIImage imageNamed:@"chatBar_colorMore_locationSelected"]];
    }
    
    return cell;
}

#pragma mark - Table view delegate
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 30;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section) {
        return nil;
    }
    
    CGRect frame = CGRectMake(0, 0, tableView.bounds.size.height, 80);
    UIView *headerView = [[UIView alloc] initWithFrame:frame];
    headerView.backgroundColor = [UIColor lightGrayColor];
    
    return headerView;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0 && indexPath.section == 0) {
        TLMapViewController *mapViewController = [[TLMapViewController alloc] init];
        mapViewController.title = @"我的位置";
        [self.navigationController pushViewController:mapViewController animated:YES];
    }
}

@end
